package com.wyf.android.advance.main

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import com.wyf.android.advance.R
import com.wyf.android.advance.activityRecycleTest.RecycleTestActivity
import com.wyf.android.advance.aidl.AidlTestActivity
import com.wyf.android.advance.rvvp.RVVPActivity
import com.wyf.android.advance.startActivityByClazz
import com.wyf.android.advance.systemversion.storage.StorageActivity
import com.wyf.android.advance.test.TestActivity
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {
    private val dataList: List<Triple<String, Boolean, ActivityStarter>> by lazy {
        listOf(
            Triple("临时测试", true) {
                startActivityByClazz(TestActivity::class.java)
            },
            Triple("Android R 存储适配", false) {
                startActivityByClazz(StorageActivity::class.java)
            },
            Triple("AIDL", true) {
                startActivityByClazz(AidlTestActivity::class.java)
            },
            Triple("MMKV", true) {
                startActivityByClazz(AidlTestActivity::class.java)
            },
            Triple("RecyclerView嵌套ViewPager", true) {
                startActivityByClazz(RVVPActivity::class.java)
            },
            Triple("Activity被回收测试", true) {
                RecycleTestActivity.start(this, "参数一", 666)
            }
        )
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        initView()
    }

    private fun initView() {
        val mainAdapter = MainAdapter()
        rv_main_list.apply {
            layoutManager = LinearLayoutManager(context)
            val divider = DividerItemDecoration(context, DividerItemDecoration.VERTICAL)
            val drawable = ContextCompat.getDrawable(context, R.drawable.line_list_divider)
            if (drawable != null) divider.setDrawable(drawable)
            addItemDecoration(divider)
            adapter = mainAdapter
        }
        mainAdapter.submitList(dataList)
    }
}

typealias ActivityStarter = () -> Unit